﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.IO.IsolatedStorage;
using System.Xml.Linq;
using System.IO;
using System.Collections.ObjectModel;
using System.Collections;
using System.Windows.Controls.DataVisualization;
using CustomControls;
using System.ComponentModel;

using ActivityTracker.Library;
using Common.Library;

namespace ActivityTracker
{
    public partial class Daily_ProgressPieChart : PhoneApplicationPage
    {
        #region Global

        Actvity objActivity = new Actvity();
        DailyChart objDailyChart = new DailyChart();
        string actId = "";

        #endregion

        #region Constructor

        public Daily_ProgressPieChart()
        {
            InitializeComponent();
        }

        #endregion

        #region Events

        private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                NavigationContext.QueryString.TryGetValue("actId", out actId);
                LoadChart();
            }
            catch (Exception ex)
            {
                string mess = "Exception in PhoneApplicationPage_Loaded Method In Daily_ProgressPieChart file.\n\n" + ex.Message + "\n\n Stack Trace:- " + ex.StackTrace;
                Exceptions.SaveOrSendExceptions(mess, ex);
            }
        }

        private void btnBarChart_Click(object sender, EventArgs e)
        {
            NavigationService.Navigate(new Uri("/Views/Charts/Daily/Daily_ProgressBarChart.xaml?actId=" + actId, UriKind.Relative));
        }

        private void labeledPieSeries_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            this.DetailsControl.Content = ((LabeledPieSeries)sender).SelectedItem;
        }

        #endregion

        #region Custom

        private void LoadChart()
        {
            try
            {
                List<ChartProp> objChartList = objDailyChart.LoadProgressData(actId);
                if (objChartList.Count > 0)
                    ContentPanel.DataContext = objChartList;
                tbkTitle.Text = objActivity.GetActivityName(actId).ToUpper();
                PieChart.LegendStyle = ChartLegendStyles.hidelegend();
            }
            catch (Exception ex)
            {
                Exception exNew = new Exception("Exception in LoadDailyPieChart Method In Daily_ProgressPieChart file.\n\n" + ex.Message + "\n\n Stack Trace:- " + ex.StackTrace);
                exNew.Data.Add("actId_LoadChart", actId);
                throw exNew;
            }
        }

        #endregion
    }
}